package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    Integer countByCategoryId(Long categoryId);


    /**
     * 新增菜品
     * @param dish
     */
    @Options(useGeneratedKeys = true,keyProperty = "id") //获取主键id
    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish values (null,#{name},#{categoryId}," +
            "#{price},#{image},#{description},#{status},#{createTime}," +
            "#{updateTime},#{createUser},#{updateUser})")
    void insert(Dish dish);

    /**
     * 分页查询菜品
     * @param dto
     * @return
     */
    Page<DishVO> selectPage(DishPageQueryDTO dto);


    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    Dish selectByIds(Long id);


    /**
     * 根据id批量删除菜品
     * @param ids
     */
    void deleteBatch(List<Long> ids);

}
